package cn.mavor.day0906;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Menu {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean validInput = false;

        while (!validInput) {
            displayMenu();
            try {
                System.out.print("请输入您的选择 (1-3): ");
                int choice = scanner.nextInt();
                scanner.nextLine(); // Consume newline left-over

                if (choice >= 1 && choice <= 3) {
                    handleChoice(choice);
                    validInput = true;
                } else {
                    System.out.println("输入的选项无效，请重新输入！");
                }
            } catch (InputMismatchException e) {
                System.out.println("输入错误！请输入一个有效的数字。");
                scanner.next(); // Clear the invalid input
            }
        }

        scanner.close();
    }

    private static void displayMenu() {
        System.out.println("请选择一个选项：");
        System.out.println("1: 登陆");
        System.out.println("2: 注册");
        System.out.println("3: 联系客服");
    }

    private static void handleChoice(int choice) {
        switch (choice) {
            case 1:
                System.out.println("您选择了：登陆");
                break;
            case 2:
                System.out.println("您选择了：注册");
                break;
            case 3:
                System.out.println("您选择了：联系客服");
                break;
        }
    }
}